package org.android.sss;

import org.android.tools.Global;
import org.android.tools.SSSHelper;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MenuActivity extends Activity {
	private Button buttonAddNewProduct;
    private Button buttonSearchForProduct;
    private Button buttonShoppingList;
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.menu);
        
        buttonAddNewProduct = (Button)findViewById(R.id.buttonAddNewProduct);
        buttonSearchForProduct = (Button)findViewById(R.id.buttonSearchForShops);
        buttonShoppingList = (Button)findViewById(R.id.buttonShoppingList);
        
        
        buttonSearchForProduct.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				Global.xCoordinate = Global.gps.getGPS()[1];
				Global.yCoordinate = Global.gps.getGPS()[0];
				if (Global.xCoordinate < 15.0) {
					Double xTmp = Global.xCoordinate;
					Global.xCoordinate = Global.yCoordinate;
					Global.yCoordinate = xTmp;
				}
				Global.shops = SSSHelper.getShopByCoordinates(Global.xCoordinate, Global.yCoordinate, "Odense");
				if (Global.shops.length != 0) {
					Global.infoSearchForProduct = "Are you there?";
				}
				else {
					Global.infoSearchForProduct = "Not found a shop where you are. \nChoose a shop from the list below.";
					
				}
				Intent myIntent = new Intent(v.getContext(), SearchForProductsActivity.class);
                startActivityForResult(myIntent,0);
			}
		});
        
        buttonAddNewProduct.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				Global.xCoordinate = Global.gps.getGPS()[1];
				Global.yCoordinate = Global.gps.getGPS()[0];
				if (Global.xCoordinate < 15.0) {
					Double xTmp = Global.xCoordinate;
					Global.xCoordinate = Global.yCoordinate;
					Global.yCoordinate = xTmp;
				}
				Global.shops = SSSHelper.getShopByCoordinates(Global.xCoordinate, Global.yCoordinate, "Odense");
				if (Global.shops.length != 0) {
					Global.infoSearchForProduct = "Are you there?";
				}
				else {
					Global.infoSearchForProduct = "Not found a shop where you are.";
					
				}
				Intent myIntent = new Intent(v.getContext(), AddNewProductActivity.class);
                startActivityForResult(myIntent,0);
			}
		});
        
        
        
        
        buttonShoppingList.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				Global.canShowOnMap = false;
				Intent myIntent = new Intent(v.getContext(), ShoppingListActivity.class);
                startActivityForResult(myIntent,0);
			}
		});
	}
}
